package org.jeecg.modules.demo.ddyht.controller;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.demo.ddyht.entity.JxcHbzj;
import org.jeecg.modules.demo.ddyht.service.IJxcHbzjService;
import org.jeecg.modules.demo.jxcx.po.JxcCustom;
import org.jeecg.modules.demo.jxcx.po.JxcCzrz;
import org.jeecg.modules.demo.jxcx.po.JxcSupplier;
import org.jeecg.modules.demo.jxcx.service.JxcCustomService;
import org.jeecg.modules.demo.jxcx.service.JxcCzrzService;
import org.jeecg.modules.demo.jxcx.service.JxcSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.UUID;

@Api(tags = "余额计算")
@RestController
@RequestMapping("/ddyht/yue")
@Slf4j
public class YueController {

    @Autowired
    private JxcSupplierService jxcSupplierService;
    @Autowired
    private JxcCustomService jxcCustomService;
    @Autowired
    private IJxcHbzjService jxcHbzjService;
    public JxcCzrz setCustom(JxcCzrz czrz, String name, String amount, String text){
        JxcCustom by = jxcCustomService.getBy(name, czrz.getCompanyId());
        BigDecimal CustomAmount = new BigDecimal(by.getAmount());
        BigDecimal amount1 = new BigDecimal(amount);
        czrz.setInfor(text + amount + "  (余额：" + CustomAmount + ")");
        return czrz;
    }
    public JxcCzrz setSupplier(JxcCzrz czrz, String name, String amount, String text){
        JxcSupplier by = jxcSupplierService.getBy(name, czrz.getCompanyId());
        BigDecimal SupplierAmount = new BigDecimal(by.getAmount());
        BigDecimal amount1 = new BigDecimal(amount);
        czrz.setInfor(text + amount + "  (余额：" + SupplierAmount + ")");
        return czrz;
    }
    public JxcCzrz setReturnSupplier(JxcCzrz czrz, String name, String amount, String text){
        JxcSupplier by = jxcSupplierService.getBy(name, czrz.getCompanyId());
        BigDecimal SupplierAmount = new BigDecimal(by.getAmount());
        BigDecimal amount1 = new BigDecimal(amount);
        czrz.setInfor(text + amount + "  (余额：" + SupplierAmount + ")");
        return czrz;
    }
    public JxcCzrz setHbzj(JxcCzrz czrz, String paymentMethod, String amount, String text) {
        JxcHbzj by = jxcHbzjService.selectbyPaymentMethod(paymentMethod, czrz.getCompanyId());
        BigDecimal HbzjAmount = new BigDecimal(by.getAmount());
        BigDecimal amount1 = new BigDecimal(amount);
        if(text.equals("-")) {
            czrz.setInfor(text + amount + "  (余额：" + HbzjAmount + ")");
            return czrz;
        }else {
            czrz.setInfor(text + amount + "  (余额：" + HbzjAmount + ")");
        }
        return czrz;
    }
}
